package com.edu.web.controller.info;

import com.edu.system.domain.TClass;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.edu.common.annotation.Log;
import com.edu.common.core.controller.BaseController;
import com.edu.common.core.domain.AjaxResult;
import com.edu.common.enums.BusinessType;
import com.edu.system.domain.TCohort;
import com.edu.system.service.ITCohortService;
import com.edu.common.utils.poi.ExcelUtil;
import com.edu.common.core.page.TableDataInfo;

/**
 * 届Controller
 *
 * @author xxxx
 * @date 2023-12-28
 */
@RestController
@RequestMapping("/system/cohort")
public class TCohortController extends BaseController {
    @Autowired
    private ITCohortService tCohortService;

    /**
     * 查询届列表
     */
    @PreAuthorize("@ss.hasPermi('system:cohort:list')")
    @GetMapping("/list")
    public TableDataInfo list(TCohort tCohort) {
        startPage();
        List<TCohort> list = tCohortService.selectTCohortList(tCohort);
        return getDataTable(list);
    }

    /**
     * 导出届列表
     */
    @PreAuthorize("@ss.hasPermi('system:cohort:export')")
    @Log(title = "届", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TCohort tCohort) {
        List<TCohort> list = tCohortService.selectTCohortList(tCohort);
        ExcelUtil<TCohort> util = new ExcelUtil<TCohort>(TCohort.class);
        util.exportExcel(response, list, "届数据");
    }

    /**
     * 获取届详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cohort:query')")
    @GetMapping(value = "/{graduationYear}")
    public AjaxResult getInfo(@PathVariable("graduationYear") String graduationYear) {
        return success(tCohortService.selectTCohortByGraduationYear(graduationYear));
    }

    /**
     * 新增届
     */
    @PreAuthorize("@ss.hasPermi('system:cohort:add')")
    @Log(title = "届", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TCohort tCohort) {
        return toAjax(tCohortService.insertTCohort(tCohort));
    }

    /**
     * 修改届
     */
    @PreAuthorize("@ss.hasPermi('system:cohort:edit')")
    @Log(title = "届", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TCohort tCohort) {
        return toAjax(tCohortService.updateTCohort(tCohort));
    }

    /**
     * 删除届
     */
    @PreAuthorize("@ss.hasPermi('system:cohort:remove')")
    @Log(title = "届", businessType = BusinessType.DELETE)
    @DeleteMapping("/{graduationYears}")
    public AjaxResult remove(@PathVariable String[] graduationYears) {
        return toAjax(tCohortService.deleteTCohortByGraduationYears(graduationYears));
    }

    /**
     * 总列表
     */
    @GetMapping("/info/allList")
    public AjaxResult allList() {
        List<TCohort> list = tCohortService.selectTCohortList(new TCohort());
        return AjaxResult.success(list);
    }
}
